package com.jl.smartcard.ui.views.filesystem;

import java.io.Serializable;

import org.eclipse.core.runtime.IAdaptable;

import com.jl.card.CardManager;
import com.jl.card.SWException;
import com.jl.card.file.CardFile;
import com.jl.smartcard.core.Logger;

class TreeEF implements IAdaptable ,Serializable{
	
	private static final long serialVersionUID = 3695288489564263921L;
	
	private String name;
	private TreeDF parent;
	private String filePath;
	
	private transient CardFile cardFile;

	public TreeEF(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setParent(TreeDF parent) {
		this.parent = parent;
	}

	public TreeDF getParent() {
		return parent;
	}

	@Override
	public String toString() {
		return getName();
	}
	
	public void setCardFile(CardFile cf){
		this.cardFile = cf;
		this.filePath = this.cardFile.path();
	}
	
	public CardFile getCardFile(){
		this.cardFile = new CardFile(CardManager.getInstance().getLastConnectCard(),this.filePath);
		this.cardFile.getCard().reset(false);
		try {
			this.cardFile.select();
		} catch (SWException e) {
			Logger.logException(e);
			return null;
		}
		return this.cardFile;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == this){
			return true;
		}else{
			if(!(obj instanceof TreeEF)){
				return false;
			}else{
				TreeEF ef = (TreeEF) obj;
				return ef.name.equals(this.name);
			}
		}
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}
	@Override
	public Object getAdapter(Class key) {
		return null;
	}
}